package com.cssy.authority.util;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

import com.byd.acegiext.domain.Action;
import com.byd.acegiext.domain.UrlPermission;
import com.byd.acegiext.domain.WebResourcePermission;
import com.byd.acegiext.permission.PermissionClassRegistry;


public class Page {
	private static final String companyId = "1";
	private int page = 1; //默认第一页
	private int pageSize = 30; //默认每页30行
	private int start = 0;
	private int end = 0;
	private String limitClause;
	public Page(HttpServletRequest request){
		initPage(request);
	}
	
	private void initPage(HttpServletRequest request){
		PermissionClassRegistry.registerAction(UrlPermission.class, Action.View);
		PermissionClassRegistry.registerAction(UrlPermission.class, Action.View);
		PermissionClassRegistry.registerAction(WebResourcePermission.class, Action.View);
		PermissionClassRegistry.registerAction(WebResourcePermission.class, Action.View);
		
		
		String strPage =request.getParameter("page");
		String strPageSize =request.getParameter("pagesize");
		if(StringUtils.isNotEmpty(strPageSize)){
			pageSize = Integer.parseInt(strPageSize);
		}
		
		if(StringUtils.isNotEmpty(strPage))
			page = Integer.parseInt(strPage);
		
		start = (page - 1) * pageSize;
		end = start + pageSize;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getEnd() {
		return end;
	}

	public void setEnd(int end) {
		this.end = end;
	}

	public static String getCompanyid() {
		return companyId;
	}

	public String getLimitClause() {
		return start + "," + pageSize;
	}

	
	
	
}
